﻿using Microsoft.Xna.Framework;


namespace LoD.WPClientLibrary.Animations {
    public class CycleColorBounce : CycleColor {
        public CycleColorBounce(int red, int green, int blue, int alpha)
            : base(red, green, blue, alpha) {
            this.Rmin = this.Gmin = this.Bmin = this.Amin = 0;
            this.Rmax = this.Gmax = this.Bmax = this.Amax = 255;
        }

        public int Amax { get; set; }
        public int Amin { get; set; }
        public int Bmax { get; set; }
        public int Bmin { get; set; }
        public int Gmax { get; set; }
        public int Gmin { get; set; }
        public int Rmax { get; set; }
        public int Rmin { get; set; }

        public override Color ModifyColor(Color original) {
            Color modified = original;

            if (!Animating) return modified;
            int r = original.R + Red;
            int g = original.G + Green;
            int b = original.B + Blue;
            int a = original.A + Alpha;

            if (r < this.Rmin) {
                r = this.Rmin;
                Red *= -1;
            } else if (r > this.Rmax) {
                r = this.Rmax;
                Red *= -1;
            }

            if (g < this.Gmin) {
                g = this.Gmin;
                Green *= -1;
            } else if (g > this.Gmax) {
                g = this.Gmax;
                Green *= -1;
            }

            if (b < this.Bmin) {
                b = this.Bmin;
                Blue *= -1;
            } else if (b > this.Bmax) {
                b = this.Bmax;
                Blue *= -1;
            }

            if (a < this.Amin) {
                a = this.Amin;
                Alpha *= -1;
            } else if (a > this.Amax) {
                a = this.Amax;
                Alpha *= -1;
            }

            modified = new Color(r, g, b, a);
            return modified;
        }
    }
}